Imports PTT.CarRes.Data

Public Class ClassQueryInvReserveTimeClostWork
    Public Function Add(ByVal InvReserveTimeClostWork As QueryInvReserveTimeClostWork) As Boolean
        Dim ClsInvReserveTimeClostWork As New ClassInvReserveTimeClostWork
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvReserveTimeClostWork.ConnectionOpen()
        Dim ret As Boolean = False
        With ClsInvReserveTimeClostWork
            .DayId = InvReserveTimeClostWork.DayId
            .ReserveDay = InvReserveTimeClostWork.ReserveDay
            .StartTime = InvReserveTimeClostWork.StartTime
            .StopTime = InvReserveTimeClostWork.StopTime
            .BdNumber = InvReserveTimeClostWork.BdNumber
            ret = .USP_Save(Conn)
        End With
        ClsInvReserveTimeClostWork.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Edit(ByVal InvReserveTimeClostWork As QueryInvReserveTimeClostWork) As Boolean
        Dim ClsInvReserveTimeClostWork As New ClassInvReserveTimeClostWork
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvReserveTimeClostWork.ConnectionOpen()
        Dim ret As Boolean = False
        With ClsInvReserveTimeClostWork
            .DayId = InvReserveTimeClostWork.DayId
            .Load(Conn)
            .ReserveDay = InvReserveTimeClostWork.ReserveDay
            .StartTime = InvReserveTimeClostWork.StartTime
            .StopTime = InvReserveTimeClostWork.StopTime
            .BdNumber = InvReserveTimeClostWork.BdNumber
            ret = .USP_Update(Conn)
        End With
        ClsInvReserveTimeClostWork.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Delete(ByVal InvReserveTimeClostWork As QueryInvReserveTimeClostWork) As Boolean
        Dim ClsInvReserveTimeClostWork As New ClassInvReserveTimeClostWork
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvReserveTimeClostWork.ConnectionOpen()
        Dim ret As Boolean = False
        With ClsInvReserveTimeClostWork
            .DayId = InvReserveTimeClostWork.DayId
            .Load(Conn)
            ret = .USP_Delete(Conn)
        End With
        ClsInvReserveTimeClostWork.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Search(Optional ByVal ParaDayId As String = "", _
    Optional ByVal ParaBdNumber As String = "") As QueryInvReserveTimeClostWorks
        Dim ClsInvReserveTimeClostWork As New ClassInvReserveTimeClostWork
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvReserveTimeClostWork.ConnectionOpen()
        Dim ret As QueryInvReserveTimeClostWorks = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvReserveTimeClostWork"
        If ParaDayId & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(DayId = " & ParaDayId & ")"
        End If
        If ParaBdNumber & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(BdNumber like '%" & ParaBdNumber & "%')"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        End If
        Dim ds As DataSet
        With ClsInvReserveTimeClostWork
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvReserveTimeClostWorks

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvReserveTimeClostWork( _
                              .Item("DayId") & "", _
                              .Item("ReserveDay") & "", _
                              .Item("StartTime") & "", _
                              .Item("StopTime") & "", _
                              .Item("BdNumber") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvReserveTimeClostWork.ConnectionClose(Conn)
        Return ret
    End Function
    Public Function Load(Optional ByVal ParaDayId As String = "", _
    Optional ByVal ParaBdNumber As String = "") As QueryInvReserveTimeClostWorks
        Dim ClsInvReserveTimeClostWork As New ClassInvReserveTimeClostWork
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvReserveTimeClostWork.ConnectionOpen()
        Dim ret As QueryInvReserveTimeClostWorks = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvReserveTimeClostWork"
        If ParaDayId & "" <> "" Then
            If Condition & "" <> "" Then Condition &= " and "
            Condition &= "(DayId = " & ParaDayId & ")"
        End If
        If ParaBdNumber & "" <> "" Then
            If Condition & "" <> "" Then Condition &= " and "
            Condition &= "(BdNumber = '" & ParaBdNumber & "')"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        Else
            Return Nothing
            Exit Function
        End If
        Dim ds As DataSet
        With ClsInvReserveTimeClostWork
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvReserveTimeClostWorks

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvReserveTimeClostWork( _
                              .Item("DayId") & "", _
                              .Item("ReserveDay") & "", _
                              .Item("StartTime") & "", _
                              .Item("StopTime") & "", _
                              .Item("BdNumber") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvReserveTimeClostWork.ConnectionClose(Conn)
        Return ret
    End Function
End Class
